import { Ref, ref } from 'vue';
import fl from '@king-fisher/falcon';
import config from '@/config/index';
import { Auth, StockInfoItem } from '@/types/pk.d';
import { Single } from '@/types/api.d';
export default (hasAuth: Ref<boolean>, isOnlyBuyOne: Ref<boolean>) => {
  const dialogIsShow = ref<boolean>(false);
  const subTitleFragment = ref<string>('');
  // 点击解锁
  const clickBuy = (stockName1: string, stockName2: string) => {
    dialogIsShow.value = true;
    subTitleFragment.value = `<span class="bold">${stockName1}</span>和<span class="bold">${stockName2}</span>`;
  };
  // 点击行数
  const clickRow = (auth: boolean, stockName: string) => {
    if (hasAuth.value && isOnlyBuyOne.value && !auth) {
      dialogIsShow.value = true;
      subTitleFragment.value = `<span class="bold">${stockName}</span>`;
    }
  };
  // 确认购买
  const gotoBuy = (
    auth1: Auth,
    auth2: Auth,
    stockCode1: StockInfoItem,
    stockCode2: StockInfoItem
  ) => {
    let paystockcode = '';
    let paystockname = '';
    if (!auth1) {
      paystockcode += `SH${stockCode1.stockCode}`;
      paystockname += `${stockCode1.stockName}`;
    }
    if (!auth2) {
      const tempStr = !paystockcode ? '' : '@';
      paystockcode += `${tempStr}SH${stockCode2.stockCode}`;
      paystockname += `${tempStr}${stockCode2.stockName}`;
    }

    fl.jumpNativePage({
      url: `client.html?action=ymtz^webid=2804^mode=new^url=${config.url.payUrl}?sid=${Single.basicSid}&paystockcode=${paystockcode}&paystockname=${paystockname}`,
    });
    dialogIsShow.value = false;
  };
  return {
    dialogIsShow,
    subTitleFragment,
    clickBuy,
    clickRow,
    gotoBuy,
  };
};
